package com.handytoo.cow.handler;

import com.handytoo.cow.protocol.Protocol;
import com.handytoo.cow.service.HelloService;
import com.handytoo.cow_core.network.Handler.EHandlerModel;
import com.handytoo.cow_core.network.Handler.anotation.HandlerMapping;
import com.handytoo.cow_core.network.Handler.anotation.HandlerModel;
import com.handytoo.cow_core.network.Session.Session;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.handytoo.cow.protocol.Protocol.*;

/**
 * @ClassName HelloHandler
 * @Description Todo
 * @Author Administrator
 * @Date 2025/6/13
 **/
@Component
@Slf4j
@HandlerModel(value = EHandlerModel.NETTY)
public class HelloHandler {
    public HelloService helloService;

    @Autowired
    public void setHelloService(HelloService helloService) {
        this.helloService = helloService;
    }
    /**
     * 获取游戏服务器信息列表
     *
     */
    @HandlerMapping(value = GetServerListRequest , auth = false)
    public ServerProto.GetServerListResponse getServerList(Session session, ServerProto.GetServerListRequest request){
        // 过滤服务器列表参数
        String type = request.getType();
        // 获取请求内容
        ServerListInfoVO serverListInfo = serverService.getServerList();
        // 转字符串
        String serverList = JSON.toJSONString(serverListInfo);
        // 拼装回应包
        ServerProto.GetServerListResponse.Builder builder = ServerProto.GetServerListResponse.newBuilder();
        builder.setServerList(serverList);
        // 返回就发送数据
        return builder.build();
    }
}
